from sqlalchemy import (
    Column,
    String,
    BigInteger,
    Text,
    Boolean,
)
from sqlalchemy.orm import relationship
from database.database import Base



class GenBusiness(Base):
    __tablename__ = "gen_business"

    id = Column(BigInteger, primary_key=True, autoincrement=True)
    app_name = Column(String(64), nullable=False, comment="应用名称（英文）")
    table_name = Column(String(256), nullable=False, unique=True, comment="表名称（英文）")
    doc_comment = Column(Text, nullable=False, default="", comment="文档注释（用于函数/参数文档) ")
    table_comment = Column(String(256), comment="表描述")
    class_name = Column(String(64), comment="基础类名（默认为英文表名称）")
    schema_name = Column(String(64), comment="Schema 名称 (默认为英文表名称)")
    filename = Column(String(64), comment="基础文件名（默认为英文表名称）")
    default_datetime_column = Column(
        Boolean, nullable=False, default=True, comment="是否存在默认时间列"
    )
    api_version = Column(
        String(32), nullable=False, default="v1", comment="代码生成 api 版本，默认为 v1"
    )
    gen_path = Column(String(256), comment="代码生成路径（默认为 app 根路径）")
    remark = Column(Text, comment="备注")

    columns = relationship("GenColumn", back_populates="business")